package 力扣;


import java.util.ArrayList;
import java.util.List;

public class leetcode46 {

    List<List<Integer>> lists=new ArrayList<>();
    List<Integer> list=new ArrayList<>();
    public static void main(String[] args) {
        int[] nums ={1,2,3};

    }

    public  List<List<Integer>> permute(int[] nums) {
        boolean[] used = new boolean[nums.length];
        backTracking(nums,used);
        return lists;
    }

    private  void backTracking(int[] nums, boolean[] used) {
        if(list.size() == nums.length){
            lists.add(new ArrayList<>(list));
            return;
        }

        for (int i = 0; i<nums.length;i++){
            if(used[i]==false){
                list.add(nums[i]);
                used[i]=true;
                backTracking(nums,used);
                used[i]=false;
                list.remove(list.size()-1);
            }
        }
    }

}



